package rabbit.topic;

/**
 * @Author: admin
 * @Description:
 * @Date: 2018/7/30 20:08
 */

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class mq {
    // dF4Rfiu9wpwNGOPl338ca/Skeh6LSHsQt8HxpJ0T8vBO0ZXbDylgbrMTHD/BSxRK3jclmeDhlNN5OF2cEJ3QdNKLnqDtn8KFwmlN3jvCC+xLGfGJWCPjpI+D2v5I8f1CVUw79l3QyvzxRtw4q6ICe9g5fQOtNo4Sd2mCRosvE5s4y/pHSe8QBuGzUnMZPqo1xuv+Bu8AVmEEdEvMO/581dNT4lOI8gaQX9IDTtClIZXScUXy17MEKXxDXYKJ0I1XNGGipWzK/zhg7Nn+F3xXb3+qHXYTXW6x0cB/GB3g+3WGP5WNiQASls0ENzwlTzEYgiGIxRnki+h4rJyPXmO1A2gMyiGgfkjP6JUtLRnlV6BZwKKj6S8J4bn3xh8pcTQHi8u58e3vCXMByZPY+QMz7Q/x9MHq2xNjzYpjSQ5ZjsIpYo/o5PYGd6cGTTMuYzRovTB4f890AeUr/MZGrnNfGfHdD7EWly0Q94e3SlywrtlWs4sVltWQHD07k1yTYq8qI5cgHDoxr182Ie4QOXVvLkEbtn/MS4hktDB5Lycnoh2TzTTjOLSjpDLV7DRkEWyyQQreia7sE0NQWpheyN3PsLbCOiRCgQEppiXP3HBtdkDfLbSHUeeqERQ8bv9NHLR1fz3KvuTogq+qbAnpWRnGIF4gSJWhBbI2MIDpTkBEUfMxokViPSOEbHa3zFk5XaLeh8mfHEHcibfrdW+x/d7DjOM3JfuUFfMBcmXLbXKIR70ci5NPFW33z3y0GsbunZvRwruQKmeHWqVvI7Vu9Daq3Ai/LxWxL1+zxN16N3Dke90eleCDtJ5TmeOGjPsPoy4/G2P2vR8/1HAdJ3iuNgprLnahDURfvnDHz/PQ+L5sPRMD/2lu7ucrf3uPQVJYcdvcjdb8etegyeHcGaTeokEmyHNNmv27vw/yDNZ75+J8HsL+0036gZHx0q9Ri7HdpgqcZBtX7GTFstynCUwWIX98u5uXONLHHqbSWszInYmL5qfC15TOG878vYrgITSNdvqn
    private static final String EXCHANGE_NAME = "outerhostexchange";

    public static void main(String[] argv) {


        Connection connection = null;
        Channel channel = null;
        try {
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("39.106.144.161");
            //factory.setHost("192.168.0.27");
            //factory.setHost("39.106.17.245");
            factory.setVirtualHost("OuterHost");
            factory.setUsername("root");
            factory.setPassword("root");
            connection = factory.newConnection();
            channel = connection.createChannel();

            channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC, true);

            String routingKey = "houseTopic";
            String message = "hello";

            String strMessage = "{\"action\":\"handpush\",\"houseInfoModels\":[{\"houseBasicInfo\":{\"entryAccount\":\"53879\",\"entryTime\":\"2018-04-14 14:26:09.0\",\"estateName\":\"盛翔里金域华府\",\"houseArea\":90,\"houseCode\":\"GF-14-90752\",\"houseDecorate\":\"精装\",\"houseDescribe\":\"2室2厅1卫1厨\",\"houseFloor\":31,\"houseNum\":\"204-1-3102\",\"houseOwnerName\":\"- -！\",\"housePrice\":150,\"isPrivate\":false,\"priceUnit\":\"万\",\"privateAccount\":\"\",\"region\":\"凤凰办事处\",\"remark\":\"房源人  楼号   唐城壹零壹 常爽 录入   照片  实勘   新一中  杨会生\",\"state\":\"已确认\",\"utype\":\"出售\"},\"imageInfos\":[{\"imageType\":\"户型图\",\"resourceCode\":\"GF-14-90752\",\"url\":\"http://tsqjcdn.eallerp.com/2015-04/115/secondhouse/1428238060116.jpg\"},{\"imageType\":\"房屋图片\",\"resourceCode\":\"GF-14-90752\",\"url\":\"http://tsqjcdn.eallerp.com/oy_yun/2018-09/D18/115/secondhouse/1537269207346.jpg\"}],\"telephoneInfos\":[{\"name\":\"- -！\",\"phoneNum\":\"18833390005\",\"resourceCode\":\"GF-14-90752\"}]}],\"mark\":\"\",\"operatorid\":\"60360\",\"utype\":\"house\"}";
            //strMessage = RSAHelper.encryptionByPublicKey(strMessage, "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCCj6y+SBwoJvn584PMKVUuw/tc8IVbrhXR3JlAYWFMpZfdS6sbcpN12nmD//wfl9SqhCbivZuPWbhaat2ILNYYjbtjBurlLqJ7nu8AVPGsMU80lJ1Jr/q1fJTYyEVX9dXS45Me/lwGta58Dv+PKRsrk9EME7azAhi1yAtavftbhwIDAQAB");
            //String hs="aOv7uS5qQaOpNam+Tnd8WWsyDriRKyXiPtTkaGEuKdF1vLbAYYRMvsPKQdmGyN/PTvK8fgOYZF7qS4CpwKyiUaHVx3DWFlbB3mHFFLfyPIiJPLA1dFWmYQ5wXRo86yQybqKrIMcHlQHkuinuyDsVy2se6G5o3IovRMW0nUCegDIxGNFOTxCwy5LPmbMSJIRzN/FoRrYDlN9AWKr43JQCFK9iQIewj2U3gcg6dOIcHvqqfrCtthzo9BH1MfwZaX1oJYPZEtCHzNYuZHAEqwPbUXad16jjN1R4+WgVR/A0QWc4KGQ4DPFWslgTVy426YoLeoosNiZw1eUu47FNXnMfGSQeATlUAFmc7NGwkvEg21PgNh31wqHDYOSyd8HV9iskhsGkwS+GbqsEvbgrKRLgGtd8T2hr5ZJfV3XrMB71YJEZ0BE8M6yC71UilTEte4Ha7UH2vsQGAgp2V+HaeVX8FnD5d8BlDQpplGJB9eP/a62AMEYlJ9tDZgqDYfqNcwRxO9I0QmxvbUNXiOluzAZRvpbyyM45qYCiHQzIRSzwvmqTPw1nigQbZGQbmXeaDPkPJce+yKe+loAAUaO0p9m/cTWkhbIX0L+3mjuagHdTj70+v7MZe0M2fHF+oUqbTfC18v+SSRZmMdV6221pqtBRcbb1S/FpeY0WlgC383/wT99yft+0qGfu6rxuJeF1wNXMObrc7VC0SlTWgF7o8Di4Bc/j2OuflQ0w5+b99YYSBjlXPOdRfwPvZ+zN5pj2F9pCMJ6+8O/130oiFsfZo2IMvnyL2xVoXJl7CEH5doDumUj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1HAdJ3iuNgprLnahDURfvnDHz/PQ+L5sPRMD/2lu7ucrf3uPQVJYcdvcjdb8etegyeHcGaTeokEmyHNNmv27vw/yDNZ75+J8HsL+0036gZHx0q9Ri7HdpgqcZBtX7GTFstynCUwWIX98u5uXONLHHqbSWszInYmL5qfC15TOG878vYrgITSNdvqn";
            channel.basicPublish(EXCHANGE_NAME, routingKey, null, strMessage.getBytes("UTF-8"));
            System.out.println(" [x] Sent '" + routingKey + "':'" + strMessage + "'");

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception ignore) {
                }
            }
        }
    }

    private static String getRouting(String[] strings) {
        if (strings.length < 1)
            return "anonymous.info";
        return strings[0];
    }

    private static String getMessage(String[] strings) {
        if (strings.length < 2)
            return "Hello World!";
        return joinStrings(strings, " ", 1);
    }

    private static String joinStrings(String[] strings, String delimiter, int startIndex) {
        int length = strings.length;
        if (length == 0) return "";
        if (length < startIndex) return "";
        StringBuilder words = new StringBuilder(strings[startIndex]);
        for (int i = startIndex + 1; i < length; i++) {
            words.append(delimiter).append(strings[i]);
        }
        return words.toString();
    }
}


